<template>
  <div class="login">
    <div class="title">美加 医美智能营销平台</div>
    <div class="form">
      <div class="mobile">
        <label for="mobile">手机:</label><input type="text" id="mobile" v-model="mobile" placeholder="请输入手机号">
      </div>
      <div class="pwd">
        <label for="pwd">密码:</label><input type="password" id="pwd" v-model="pwd" placeholder="请输入密码">
      </div>
      <div class="submit" @click="login">
        登录
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "Login",
  data() {
    return {
      mobile: "",
      pwd: ""
    };
  },
  created() {},
  methods: {
    login() {
      // alert(this.mobile + "," + this.pwd)
      // this.$store.commit("login", this.mobile);
      // this.$router.push({ path: "/search" });
      this.$http({
        url: "web/user/login",
        method: "post",
        data: {
          phone: this.mobile,
          password: this.pwd
        },
        withCredentials: true
      })
        .then(res => {
          if (res.data.success === false) {
            alert(res.data.error);
          } else {
            this.$store.commit("login", this.mobile);
            this.$router.push({ path: "/search" });
          }
        })
        .catch(err => {
          console.log(err);
        });
    }
  }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="scss">
.login {
  margin: 10% auto;
  width: 800px;
  height: 300px;
  padding: 30px;
  .title {
    font-size: 20px;
    text-align: center;
  }
  .form {
    width: 80%;
    margin: 40px auto;
    .mobile {
      height: 40px;
      font-size: 18px;
      margin-bottom: 30px;
      input {
        width: 80%;
        border: 1px solid black;
        line-height: 30px;
        margin-left: 20px;
      }
    }
    .pwd {
      height: 40px;
      font-size: 18px;
      margin-bottom: 30px;
      input {
        width: 80%;
        border: 1px solid black;
        line-height: 30px;
        margin-left: 20px;
      }
    }
    .submit {
      width: 80%;
      margin: 0 auto;
      text-align: center;
      background-color: rgba(22, 155, 213, 1);
      line-height: 40px;
    }
  }
}
</style>
